Yacon.widget.TDropDate = function(element){
	if(element){
		this.element = element;
	}	
};

Yacon.widget.TDropDate.prototype = {
	
	/* 获取HTML信息 */	
	getHtml: function(){
		
		var html = "";
		
		html += this.getDateHtml();
		
		return html;
		
	},
	
	getDateHtml: function(){
		
		var html = "";
		
		if(this.isEnable()){
			
			var default_date = this.getDefaultValue();
			
			html += "<div class='input-group date form_date' data-date='"+Yacon.getNowFormatDate()+"' data-date-format='yyyy-mm-dd' data-link-format='yyyy-mm-dd' ";		
			html += " data-link-field='"+this.element.name+"' ";		
			html += ">";
			
			var lableClass = "";
			
			if(this.isEnable() || this.parent.view.isStatic){
				lableClass += "bk-bg-primary";
			}else{
				lableClass += "bk-bg-brown";
			}
			
			if(this.element.btnState){
				lableClass = "bk-bg-"+this.element.btnState;
			}
			
			/* 名称部分 */
			if(Yacon.isTrue(this.element.lableVisible)){
				html += "<span class='input-group-btn "+lableClass+"' "+this.getColorStyle()+" >";
				
/*				html += "<button class='btn "+lableClass+"' "+this.getColorStyle()+" type='button'>";
				html += this.getLableHtml();
				html += "</button>";*/
				
				html += new Yacon.widget.TButton(this.element.labelMenu).getFormHtml();
				
				html += "</span>";
			}
			
			html += "<input class='form-control lily-fix-field' field-fix-name='"+this.element.name+"' size='16' type='text' value='"+default_date+"' readonly/>";
			//html += "<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>";
			html += "<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>";
			html += "<input class='lily-field' field-type='date' name='"+this.element.name+"' field-name='"+this.element.name+"' type='hidden' id='"+this.element.name+"' value='"+default_date+"' />";
			
			html += "</div>";

			
		}else{
			
			html += this.getDisableHtml();
			
		}
		
		
		return html;
		
	},
	
	getTimeHtml: function(){
		
		var html = "";
		
		if(this.isEnable()){
			
			var default_date = this.getDefaultValue();
			
			html += "<div class='input-group date form_time' data-date='"+Yacon.getNowFormatTime()+"' data-date-format='hh:ii:ss' data-link-format='hh:ii:ss' ";		
			html += " data-link-field='"+this.element.name+"' ";		
			html += ">";
			
			var lableClass = "";
			
			if(this.isEnable() || this.parent.view.isStatic){
				lableClass += "bk-bg-primary";
			}else{
				lableClass += "bk-bg-brown";
			}
			
			if(this.element.btnState){
				lableClass = "bk-bg-"+this.element.btnState;
			}
			
			/* 名称部分 */
			if(Yacon.isTrue(this.element.lableVisible)){
				html += "<span class='input-group-btn "+lableClass+"' "+this.getColorStyle()+" >";
				
/*				html += "<button class='btn "+lableClass+"' "+this.getColorStyle()+" type='button'>";
				html += this.getLableHtml();
				html += "</button>";*/
				
				html += new Yacon.widget.TButton(this.element.labelMenu).getFormHtml();
				
				html += "</span>";
			}
			
			html += "<input class='form-control lily-fix-field' field-fix-name='"+this.element.name+"' size='16' type='text' value='"+default_date+"' readonly/>";
			//html += "<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>";
			html += "<span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span>";
			html += "<input class='lily-field' field-type='date' name='"+this.element.name+"' field-name='"+this.element.name+"' type='hidden' id='"+this.element.name+"' value='"+default_date+"' />";
			
			html += "</div>";
			
		}
		else{
			
			html += this.getDisableHtml();
			
		}
			
		return html;
		
	},
	
	getDateTimeHtml: function(){
		
		var html = "";
		
		if(this.isEnable()){
			
			var default_date = this.getDefaultValue();
			
			html += "<div class='input-group date form_datetime' data-date='"+Yacon.getNowFormatDateTime()+"' data-date-format='yyyy-mm-dd hh:ii:ss'  ";		
			html += " data-link-field='"+this.element.name+"' ";		
			html += ">";
			
			var lableClass = "";
			
			if(this.isEnable() || this.parent.view.isStatic){
				lableClass += "bk-bg-primary";
			}else{
				lableClass += "bk-bg-brown";
			}
			
			if(this.element.btnState){
				lableClass = "bk-bg-"+this.element.btnState;
			}
			
			/* 名称部分 */
			if(Yacon.isTrue(this.element.lableVisible)){
				html += "<span class='input-group-btn "+lableClass+"' "+this.getColorStyle()+" >";
				
				/*html += "<button class='btn "+lableClass+"' "+this.getColorStyle()+" type='button'>";
				html += this.getLableHtml();
				html += "</button>";*/
				
				html += new Yacon.widget.TButton(this.element.labelMenu).getFormHtml();
				
				html += "</span>";
			}

			html += "<input class='form-control lily-fix-field' field-fix-name='"+this.element.name+"' size='16' type='text' value='"+default_date+"' readonly/>";
			//html += "<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>";
			html += "<span class='input-group-addon'><span class='glyphicon glyphicon-th'></span></span>";
			html += "<input class='lily-field' field-type='date' name='"+this.element.name+"' field-name='"+this.element.name+"' type='hidden' id='"+this.element.name+"' value='"+default_date+"' />";
			
			html += "</div>";
			
		}else{
			html += this.getDisableHtml();
		}
		
		return html;
		
	},
	
	getTimestampHtml: function(){
		
		var html = "";
		
		if(this.isEnable()){
			
			var default_date = this.getDefaultValue();
			
			html += "<div class='input-group date form_datetime' data-date='"+Yacon.getNowFormatDateTime()+"' data-date-format='yyyy-mm-dd hh:ii:ss'  ";		
			html += " data-link-field='"+this.element.name+"' ";		
			html += ">";
			
			var lableClass = "";
			
			if(this.isEnable() || this.parent.view.isStatic){
				lableClass += "bk-bg-primary";
			}else{
				lableClass += "bk-bg-brown";
			}
			
			if(this.element.btnState){
				lableClass = "bk-bg-"+this.element.btnState;
			}
			
			/* 名称部分 */
			if(Yacon.isTrue(this.element.lableVisible)){
				html += "<span class='input-group-btn "+lableClass+"' "+this.getColorStyle()+" >";
				
				/*html += "<button class='btn "+lableClass+"' "+this.getColorStyle()+" type='button'>";
				html += this.getLableHtml();
				html += "</button>";*/
				
				html += new Yacon.widget.TButton(this.element.labelMenu).getFormHtml();
				
				html += "</span>";
			}
			
			html += "<input class='form-control lily-fix-field' field-fix-name='"+this.element.name+"' size='16' type='text' value='"+default_date+"' readonly/>";
			//html += "<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>";
			html += "<span class='input-group-addon'><span class='glyphicon glyphicon-th'></span></span>";
			html += "<input class='lily-field' field-type='date' name='"+this.element.name+"' field-name='"+this.element.name+"' type='hidden' id='"+this.element.name+"' value='"+default_date+"' />";
			
			html += "</div>";

		}
		
		else{
			
			html += this.getDisableHtml();
			
		}
		
		return html;
		
	},
	
	getDisableHtml: function(){
		
		var html = "";
			
		html += "<div class='input-group'>";
		
		if(this.parent.view.isStatic){
			
			var lableClass = "bk-bg-primary";
			
			if(this.element.btnState){
				lableClass = "bk-bg-"+this.element.btnState;
			}
			
			html += "<span class='input-group-btn "+lableClass+"' "+this.getColorStyle()+" >";	
			html += "<button class='btn "+lableClass+"' "+this.getColorStyle()+" type='button'>";
		}else{
			html += "<span class='input-group-btn lily-button-form'>";	
			html += "<button class='btn lily-button-form' type='button'>";
		}
		
		html += this.getLableHtml();
		html += "</button>";
		html += "</span>";
		
		html += "<input ";
		
		html += " id='"+this.element.name+"' ";
		html += " class='form-control lily-field' name='"+this.element.name+"' type='text' ";
		
		html += " field-name='"+this.element.name+"' ";
		
		if(this.element.blank){
			html += " placeholder='"+this.element.blank+"' ";
		}
			
		html += " disabled ";
			
		html += " />";
		
		html += "</div>";
		
		return html;
		
	},
	
	getDefaultValue: function(){
		
		this.page = this.parent.page;
		var state = this.page.element.parameter.state;
		
		if(Yacon.isEmpty(state)){
			state = "active";
		}
		
		if(!Yacon.isEmpty(this.element.commonVal)){			
			return " "+this.element.commonVal+" ";		
		}
		
		else{
			
			if(state == "insert"){
				if(!Yacon.isEmpty(this.element.insertVal)){			
					return " "+this.element.insertVal+" ";		
				}else{
					return "";
				}
			}
			
			else if(state == "edit"){
				if(!Yacon.isEmpty(this.element.editVal)){			
					return ""+this.element.editVal+" ";	
				}else{
					return "";
				}
			}
			
			else {
				return "";
			}
			
		}
	},
	
	addEvent: function(){
		
		$('.form_datetime').datetimepicker({
	        language:  'zh-CN',
	        weekStart: 1,
	        todayBtn:  1,
			autoclose: 1,
			clearBtn:1,
			todayHighlight: 1,
			startView: 2,
			forceParse: 0,
	        showMeridian: 1
	    });
		$('.form_date').datetimepicker({
	        language:  'zh-CN',
	        weekStart: 1,
	        todayBtn:  1,
			autoclose: 1,
			clearBtn:1,
			todayHighlight: 1,
			startView: 2,
			minView: 2,
			forceParse: 0
	    });
		$('.form_time').datetimepicker({
	        language:  'zh-CN',
	        weekStart: 1,
	        todayBtn:  1,
			autoclose: 1,
			clearBtn:1,
			todayHighlight: 1,
			startView: 1,
			minView: 0,
			maxView: 1,
			forceParse: 0,
			startDate:Yacon.getNowFormatDate()
	    });
		
	},

	isEnable: function(){
		
		this.page = this.parent.page;
		var state = this.page.element.parameter.state;
		
		if(Yacon.isEmpty(state)){
			state = "active";
		}
		
		if(!this.element.isEnable){
			return false;
		}
		
		if(state == "insert"){
			return this.element.isInsert;
		}else if(state == "edit"){
			return this.element.isEdit;
		}else if(state == "past"){
			return false;
		}
		else{
			return true;
		}
		
	},
	
	getLableHtml: function(){
		
		var html = "";
		var lable = this.element.text;
		var lableIco = this.element.ico;
		var lableType = this.element.viewType;
		
		if(Yacon.isEmpty(lableIco)){
			lableIco = "glyphicon glyphicon-tag";
		}
		
		if(lableType == "all"){
			html += "<span class='"+lableIco+"'></span>&nbsp;&nbsp;"+lable;
		}
		else if(lableType == "ico"){
			html += "<span class='"+lableIco+"'></span>";
		}
		else if(lableType == "label"){
			html += lable;
		}
		
		return html;
	},
	
	getColorStyle: function(){
		
		var html = "";
		
		var btnColor = "";
		
		if(!Yacon.isEmpty(this.element.fontColor)){
			btnColor += "color:"+this.element.fontColor+" !important;";
		}
		
		if(!Yacon.isEmpty(this.element.backColor)){
			btnColor += " background-color:"+this.element.backColor+" !important;";
			btnColor += " border-color:"+this.element.backColor+" !important;";
		}
		
		if(!Yacon.isEmpty(btnColor)){
			html += " style='"+btnColor+"' ";
		}
		
		return html;
		
	}

};